#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int mod=998244353,inf=0x3f3f3f3f3f3f3f3f;
int n,a[100010],b[100010],ans;
int nxt(int x){return x%n+1;}
map<int,int>mp;
void calc()
{
	int hsh=0,base=1;
	for ( int i = 1 ; i <= n ; i++ )
	{
		hsh=(hsh+base*b[i]%1147744151)%1147744151;
		base=base*147744151;
	}
	if(mp[hsh])return;
	mp[hsh]=1;
//	for ( int i = 1 ; i <= n ; i++ )cout << b[i] << " ";
//	cout << endl;
	int mul=1;
	for ( int i = 1 ; i <= n ; i++ )mul=mul*(a[nxt(i)]+b[i]-b[nxt(i)])%mod;
	ans=(ans+mul)%mod;
}
void dfs(int x,int nn)
{
	if(x==nn)return calc(),void();
	for ( int i = 0 ; i <= a[x] ; i++ )
	{
		b[x]=i;
		dfs(nxt(x),nn);
	}
	b[x]=0;
}
int check()
{
	int cnt=0;
	for ( int i = 1 ; i <= n ; i++ )
	{
		cnt+=a[i];
		if(a[i]>=2)return 0;
	}
	return cnt;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("trade.in","r",stdin);
	freopen("trade.out","w",stdout);
	cin >>n;
	for ( int i = 1 ; i <= n ; i++ )cin >> a[i];
	if(check())return cout << (check()==n),0;
	for ( int i = 1 ; i <= n ; i++ )dfs(nxt(i),i);
	cout << ans;
	return 0;
}//20
